package MyTest;

import MyTest.MyRunnable;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.*;

public class Server {

    public Server() throws IOException {
        //创建线程池对象
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                3,
                6,
                60,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );

        ServerSocket ss = new ServerSocket(10000);

        while (true)
        {
            //获取客户端socket
            Socket socket = ss.accept();
            System.out.println("有客户端来连接");
            //交给线程池管理
            pool.submit(new MyRunnable(socket));
        }


    }

}
